<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>Welcome to CodeIgniter</title>

<style type="text/css">

body {
 background-color: #fff;
 margin: 40px;
 font-family: Lucida Grande, Verdana, Sans-serif;
 font-size: 14px;
 color: #4F5155;
}

a {
 color: #003399;
 background-color: transparent;
 font-weight: normal;
}

h1 {
 color: #444;
 background-color: transparent;
 border-bottom: 1px solid #D0D0D0;
 font-size: 16px;
 font-weight: bold;
 margin: 24px 0 2px 0;
 padding: 5px 0 6px 0;
}

code {
 font-family: Monaco, Verdana, Sans-serif;
 font-size: 12px;
 background-color: #f9f9f9;
 border: 1px solid #D0D0D0;
 color: #002166;
 display: block;
 margin: 14px 0 14px 0;
 padding: 12px 10px 12px 10px;
}

</style>
</head>
<body>

<h1>Welcome to CodeIgniter!</h1>

<p>The page you are looking at is being generated dynamically by CodeIgniter.</p>

<p>If you would like to edit this page you'll find it located at:</p>
<code>application/views/welcome_message.php</code>

<p>The corresponding controller for this page is found at:</p>
<code>application/controllers/welcome.php</code>

<p>If you are exploring CodeIgniter for the very first time, you should start by reading the <a href="user_guide/">User Guide</a>.</p>


<p><br />Page rendered in {elapsed_time} seconds</p>

<!-- 测试 -->
<?php
function my_echo($var='') {
	echo $var.'<br/>';
}
$arr = array(
	'hello',
	42,
	array(1,'two'),
	'apple'
);

$string = serialize($arr);//序列化
my_echo($string);

$newarr = unserialize($string);//反序列化
print_r($newarr);
my_echo();

$string = json_encode($arr);//数组转JSON
my_echo($string);

$newarr = json_decode($string);//JSON转数组
print_r($newarr);
?>
<br/>
<?php
//递归测试
$rows = array(
    array(
        'id' => 1,
        'name' => 'dev',
        'parentid' => 0
    ),
    array(
        'id' => 2,
        'name' => 'php',
        'parentid' => 1
    ),
    array(
        'id' => 3,
        'name' => 'smarty',
        'parentid' => 2
    ),
    array(
        'id' => 4,
        'name' => 'life',
        'parentid' => 0
    ),
    array(
        'id' => 5,
        'name' => 'pdo',
        'parentid' => 2
    ),
    array(
        'id' => 6,
        'name' => 'pdo-mysql',
        'parentid' => 5
    ),
    array(
        'id' => 7,
        'name' => 'java',
        'parentid' => 1
    )
);

function findChild(&$arr,$id){
	$childs=array();
	foreach ($arr as $k =>$v){
		if($v['parentid']== $id){
			$childs[]=$v;
		}
	}
	return $childs;
}

function build_tree($rows,$id){
	$childs=findChild($rows,$id);
	if(empty($childs)){
		return null;
	}
	foreach ($childs as $k => $v){
		$rescurTree=build_tree($rows,$v['id']);
		if( null != $rescurTree){
			$childs[$k]['childs']=$rescurTree;
		}
	}
	return $childs;
}
$tree=build_tree($rows,0);
//echo memory_get_usage();
print_r($tree);
?>
</body>
</html>